package com.yhd.rabbit.one;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.yhd.rabbit.util.ConnectionUtil;

import java.nio.charset.StandardCharsets;

/**
 * @author 二十
 * @since 2022/1/13 11:48 下午
 */
public class SenderA {

    private static final String QUEUE_NAME = "one_queue";

    public static void main(String[] args) throws Exception {
        //1.获取连接
        Connection conn = ConnectionUtil.getConnection();
        //2.创建通道。使用通道才能推送消息
        Channel channel = conn.createChannel();
        //3.创建队列
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        //4.构建消息内容
        String message = "Hello,RabbitMQ!";
        //5.往指定的队列发送消息
        channel.basicPublish("", QUEUE_NAME, null, message.getBytes(StandardCharsets.UTF_8));
        //6.关闭通道&连接
        channel.close();
        conn.close();
    }
}
